import java.net.*;
import java.io.*;

public class ProxyClient {

	/**
	 * http://docstore.mik.ua/orelly/java-ent/dist/ch02_01.htm
	 * @param args
	 * @throws IOException 
	 * @throws UnknownHostException 
	 */
	public static void main(String[] args) throws UnknownHostException, IOException {
		String s_ip = "192.168.1.7";
		int s_port = 9090;
		ProxyClient client = new ProxyClient(s_ip, s_port);
		client.run();
		client.tearDown();
		
	}
	Socket csSocket; //UDT in the furture
	ObjectInputStream readFromServer;
	ObjectOutputStream writeToServer;
	
	public ProxyClient(String s_ip, int s_port) throws UnknownHostException, IOException{
		csSocket =new Socket(s_ip,s_port);
		

	}
	public void run() throws IOException{
		readFromServer = new ObjectInputStream( csSocket.getInputStream() );
		writeToServer = new ObjectOutputStream( csSocket.getOutputStream() );
		
		writeToServer.writeUTF("Hi this is client 007");
		String line = readFromServer.readUTF();
		System.out.println(line);
	}
	public void tearDown() throws IOException{
		if(readFromServer.read()==-1){
			csSocket.close();
			writeToServer.close();
		}

		

	}

}
